package com.huawei.hwid.api.common;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.Uri;
import android.os.Parcelable;
import android.provider.MediaStore.Images.Media;
import android.widget.ArrayAdapter;
import com.huawei.hwid.core.d.l;
import com.huawei.hwid.core.d.o;
import com.huawei.hwid.f.e;

public class c extends Builder {
    private AlertDialog a;
    private Activity b;
    private Uri c;

    public c(Activity activity, Uri uri) {
        super(activity, o.a(activity));
        this.b = activity;
        this.c = uri;
        setAdapter(new ArrayAdapter(this.b, 17367043, 16908308, new CharSequence[]{activity.getResources().getString(l.a(this.b, "CloudSetting_take_picture")), activity.getResources().getString(l.a(this.b, "hwid_string_choose_from_gallery")), activity.getResources().getString(17039360)}), new OnClickListener(this) {
            final /* synthetic */ c a;

            {
                this.a = r1;
            }

            public void onClick(DialogInterface dialogInterface, int i) {
                switch (i) {
                    case 0:
                        this.a.b();
                        return;
                    case 1:
                        this.a.c();
                        return;
                    case 2:
                        this.a.a();
                        return;
                    default:
                        return;
                }
            }
        });
    }

    public AlertDialog show() {
        this.a = super.show();
        return this.a;
    }

    private void b() {
        if (this.c != null) {
            Parcelable a = e.a(this.b, this.c.getPath());
            if (a != null) {
                com.huawei.hwid.core.d.b.e.b("AddPicDialog", "start Camare", true);
                Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
                intent.putExtra("output", a);
                try {
                    this.b.startActivityForResult(intent, 1003);
                    return;
                } catch (Exception e) {
                    this.a.cancel();
                    com.huawei.hwid.core.d.b.e.d("AddPicDialog", "start Camare :", true);
                    return;
                }
            }
        }
        this.a.cancel();
    }

    private void c() {
        Intent intent = new Intent("android.intent.action.PICK", null);
        intent.setDataAndType(Media.EXTERNAL_CONTENT_URI, "image/*");
        try {
            this.b.startActivityForResult(intent, 1004);
        } catch (Exception e) {
            this.a.cancel();
            com.huawei.hwid.core.d.b.e.d("AddPicDialog", "start Gallery :", true);
        }
    }

    public void a() {
        if (this.a != null && this.a.isShowing()) {
            this.a.cancel();
        }
    }
}
